import 'package:flutter/material.dart';

///点击几次可触发
// ignore: must_be_immutable
class GestureDetectorExt extends StatelessWidget {
  final Widget child;

  ///点击多少次触发
  final int numberOfTap;
  final Duration duration;
  void Function()? onTap;
  GestureDetectorExt(
      {super.key,
      required this.child,
      required this.numberOfTap,
      this.onTap,
      this.duration = const Duration(seconds: 3)});

  var _tapTimes = 0;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: child,
      onTap: () {
        _tapTimes++;
        if (_tapTimes > numberOfTap) {
          onTap?.call();
          _tapTimes = 0;
        }
        Future.delayed(duration, () => _tapTimes = 0);
      },
    );
  }
}
